package com.github.shiqiyue.blog.markdown.entity;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Transient;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import lombok.Data;

/****
 * 会员
 * 
 * @author wwy
 *
 */
@Data
@Entity(name = "blog_user")
public class User implements UserDetails {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -164337608917052650L;
	
	public static final List<SimpleGrantedAuthority> DEFAULT_GRANT_AUTHORITIES = new ArrayList<>(
			Arrays.asList(new SimpleGrantedAuthority("ROLE_USER")));
	
	/***
	 * id
	 */
	@Id
	@GeneratedValue
	private Long id;
	
	/***
	 * 用户名
	 */
	private String username;
	
	/***
	 * 密码
	 */
	private String password;
	
	/***
	 * email
	 */
	private String email;
	
	/***
	 * 添加时间
	 */
	@Column(name = "add_date")
	private Date addDate;
	
	@Transient
	private boolean accountNonExpired = true;
	
	@Transient
	private boolean accountNonLocked = true;
	
	@Transient
	private boolean credentialsNonExpired = true;
	
	@Transient
	private boolean enabled = true;
	
	@Transient
	private List<SimpleGrantedAuthority> authorities = DEFAULT_GRANT_AUTHORITIES;
	
	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		return authorities;
	}
	
	@Override
	public boolean isAccountNonExpired() {
		return accountNonExpired;
	}
	
	@Override
	public boolean isAccountNonLocked() {
		return accountNonLocked;
	}
	
	@Override
	public boolean isCredentialsNonExpired() {
		return credentialsNonExpired;
	}
	
	@Override
	public boolean isEnabled() {
		return enabled;
	}
}
